<template>
  <div class="list-table">
    <div class="table-row table-header flex">
      <div class="flex-2 th">姓名</div>
      <div class="flex-2 th">手机</div>
      <div class="flex-2 th" v-if="tableName === 'recording'">划转方向</div>
      <div class="flex-2 th" v-if="tableName === 'recording'">划转金额(元)</div>
      <div class="flex-2 th">余额(元)</div>
      <div class="flex-2 th">{{ tableName === 'recording' ? '操作时间' : '创建时间' }}</div>
      <div class="flex-3 th" v-if="tableName !== 'recording'">操作</div>
    </div>
    <div class="table-row table-body-row flex" v-for="(item, index) in tableList" :key="item.phone + '_' + index">
      <div class="flex-2 td">{{ item.name }}</div>
      <div class="flex-2 td">{{ item.phone }}</div>
      <div class="flex-2 td" v-if="tableName === 'recording'">
        <span class="direction" :class="{ 'text-danger': item.direction != 1 }">
          {{ item.direction == 1 ? '充值' : '扣款' }}
        </span>
      </div>
      <div class="flex-2 td" v-if="tableName === 'recording'">{{ item.variety }}</div>
      <div class="flex-2 td">{{ item.amount }}</div>
      <div class="flex-2 td">{{ item.createTime }}</div>
      <div class="flex-3 td" v-if="tableName !== 'recording'">
        <span class="text-btn" @click="handelBtn('recharge', item)">充值</span>
        <span class="text-btn" @click="handelBtn('deduction', item)">扣款</span>
        <span class="text-btn" @click="handelBtn('recording', item)">交易记录</span>
        <span class="text-btn text-danger" @click="handelBtn('del', item)">删除</span>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'

@Component
export default class Dialog extends Vue {
  @Prop({ default: [] })
  tableList: Array<object> | undefined

  @Prop({ default: 'list' })
  tableName: string | undefined

  handelBtn(type: string, item: object) {
    this.$emit('handelBtn', { type, item })
  }
}
</script>
<style lang="scss" scoped>
.list-table {
  overflow-y: auto;
  padding: 10px 0;

  .table-row {
    height: 44px;
    line-height: 44px;

    .th,
    .td {
      padding: 0 8px;
    }

    .td {
      color: #666;
    }

    .th {
      color: #000;
    }

    .text-btn {
      cursor: pointer;
      color: seagreen;

      & + .text-btn {
        padding-left: 20px;
      }
    }

    .direction {
      color: #67c23a;
    }
  }

  .table-body-row:nth-child(odd) {
    background: rgba($color: #999, $alpha: 0.1);
  }

  .table-header {
    border-bottom: 1px solid #000;
  }
}
</style>
